package com.example.club.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.club.R
import com.example.club.model.CarActivityItem

class CarActivityAdapter(private val items: List<CarActivityItem>) :
    RecyclerView.Adapter<CarActivityAdapter.ViewHolder>() {

    class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val ivCover: ImageView = view.findViewById(R.id.iv_cover)
        val tvStatus: TextView = view.findViewById(R.id.tv_status)
        val tvTitle: TextView = view.findViewById(R.id.tv_title)
        val tvOfficial: TextView = view.findViewById(R.id.tv_official)
        val tvHot: TextView = view.findViewById(R.id.tv_hot)
        val tvSignupCount: TextView = view.findViewById(R.id.tv_signup_count)
        val tvTime: TextView = view.findViewById(R.id.tv_time)
        val tvDistance: TextView = view.findViewById(R.id.tv_distance)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_car_activity, parent, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = items[position]
        holder.ivCover.setImageResource(item.imageRes)
        holder.tvStatus.text = item.status
        holder.tvTitle.text = item.title
        holder.tvOfficial.visibility = if (item.isOfficial) View.VISIBLE else View.GONE
        holder.tvHot.visibility = if (item.isHot) View.VISIBLE else View.GONE
        holder.tvSignupCount.text = "${item.signupCount}人报名"
        holder.tvTime.text = item.time
        holder.tvDistance.text = item.distance
    }

    override fun getItemCount(): Int = items.size
} 